package com.zhangyongyi.carhome.fragment.recommend;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zhangyongyi.carhome.R;
import com.zhangyongyi.carhome.adapter.recommend.RecommendAdapter;
import com.zhangyongyi.carhome.fragment.recommend.evaluating.EvaluatingFragment;
import com.zhangyongyi.carhome.fragment.recommend.newest.NewestFragment;
import com.zhangyongyi.carhome.fragment.recommend.news.NewsFragment;
import com.zhangyongyi.carhome.fragment.recommend.persuader.PersuaderFragment;
import com.zhangyongyi.carhome.fragment.recommend.technology.TechnologyFragment;
import com.zhangyongyi.carhome.fragment.recommend.usevihicle.UseVihicleFragment;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/7.
 * 推荐
 */
public class RecommendFragment extends Fragment{

    private ArrayList<Fragment> datas;
    private ViewPager viewPager;
    private RecommendAdapter adapter;
    private TabLayout tabLayout;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_recommend,null);

        return v;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        datas = new ArrayList<>();
        datas.add(new NewestFragment());//最新
        datas.add(new NewsFragment());//新闻
        datas.add(new EvaluatingFragment());//评测
        datas.add(new UseVihicleFragment());//用车
        datas.add(new TechnologyFragment());//技术
        datas.add(new PersuaderFragment());//说课

        viewPager = (ViewPager) view.findViewById(R.id.viewpager_recommend);
        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout_recommend);
        adapter = new RecommendAdapter(getFragmentManager(),datas,getActivity());
        viewPager.setAdapter(adapter);
        //蓝色
        tabLayout.setSelectedTabIndicatorColor(Color.BLUE);
        tabLayout.setupWithViewPager(viewPager);
        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            if (tab != null){
                tab.setCustomView(adapter.getTabView(i));
            }
        }

        viewPager.setCurrentItem(1);
    }
}
